package dbtypes

import "time"

type (
	Balance struct {
		RawBalance   int64
		CleanBalance int64
	}
)

type (
	BalanceGetRequest struct {
		OwnerId string
	}

	BalanceGetResponse struct {
		Balance *Balance
	}
)

type (
	BalanceCreateRequest struct {
		Id           string
		OwnerId      string
		RawBalance   int64
		CleanBalance int64
	}
)

type TransactionStatus string

const (
	TransactionStatusNew      TransactionStatus = "new"
	TransactionStatusPending  TransactionStatus = "pending"
	TransactionStatusApproved TransactionStatus = "approved"
	TransactionStatusRejected TransactionStatus = "rejected"
)

func NewTransactionStatus(status *string) *TransactionStatus {
	if status == nil {
		return nil
	}

	res := TransactionStatus(*status)

	return &res
}

type TransactionType string

const (
	TransactionTypeDeposit    TransactionType = "deposit"
	TransactionTypeWithdrawal TransactionType = "withdrawal"
)

func NewTransactionType(typ *string) *TransactionType {
	if typ == nil {
		return nil
	}

	res := TransactionType(*typ)

	return &res
}

type (
	Transaction struct {
		Id              string
		OwnerInfo       *TransactionOwnerInfo
		BankAccountInfo *BankAccountInfo
		Type            TransactionType
		Status          TransactionStatus
		Amount          int64
		Currency        string
		CreatedAt       time.Time
		Payload         *TransactionPayload
	}

	BankAccountInfo struct {
		Id                   string
		AccountNumber        string
		AccountName          string
		BankName             string
		Bik                  string
		CorrespondentAccount string
		OwnerType            string
	}

	TransactionOwnerInfo struct {
		Id   string
		Name string
	}

	// TODO: make DB migration to use this
	// TransactionPayload struct {
	// 	Origin      string              `json:"origin"`
	// 	CompanyInfo *PayloadCompanyInfo `json:"company_info"`
	// 	VacancyInfo *PayloadVacancyInfo `json:"vacancy_info"`
	// }

	// PayloadCompanyInfo struct {
	// 	Id   string `json:"id"`
	// 	Name string `json:"name"`
	// }

	// PayloadVacancyInfo struct {
	// 	Id   string `json:"id"`
	// 	Name string `json:"name"`
	// }

	TransactionPayload struct {
		Origin      string `json:"origin"`
		CompanyId   string `json:"company_id"`
		CompanyName string `json:"company_name"`
		VacancyId   string `json:"vacancy_id"`
		VacancyName string `json:"vacancy_name"`
	}
)

type (
	TransactionListGetRequest struct {
		OwnerId  string
		Filters  *TransactionListFilters
		Page     uint64
		PageSize uint64
	}

	TransactionListFilters struct {
		Type          *TransactionType
		Status        *TransactionStatus
		BankAccountId *string
	}

	TransactionListGetResponse struct {
		Transactions []Transaction
	}
)

type (
	TransactionCreateRequest struct {
		OwnerId       string
		Amount        int64
		Currency      string
		BankAccountId *string
		RequestId     string
		Payload       *TransactionPayload
	}

	TransactionCreateResponse struct {
		Id string
	}
)

type (
	BankAccount struct {
		Id                   string
		OwnerId              string
		AccountNumber        string
		AccountName          string
		BankName             string
		Bik                  string
		CorrespondentAccount string
		IsPrimary            bool
		CreatedAt            time.Time
		UpdatedAt            time.Time
	}
)

type (
	BankAccountListGetRequest struct {
		OwnerId string
	}

	BankAccountListGetResponse struct {
		BankAccounts []BankAccount
	}
)

type (
	BankAccountCreateRequest struct {
		OwnerId              string
		AccountNumber        *string
		AccountName          *string
		BankName             *string
		Bik                  *string
		CorrespondentAccount *string
		IsPrimary            *bool
	}

	BankAccountCreateResponse struct {
		Id string
	}
)

type (
	BankAccountUpdateRequest struct {
		Id                   string
		AccountNumber        *string
		AccountName          *string
		BankName             *string
		Bik                  *string
		CorrespondentAccount *string
		IsPrimary            *bool
	}

	BankAccountUpdateResponse struct{}
)

type (
	BankAccountDeleteRequest struct {
		Id      string
		OwnerId string
	}

	BankAccountDeleteResponse struct{}
)
