package database

import (
	"context"

	dberrors "git-molva.ru/Molva/molva-backend/services/api_gateway/internal/database/errors"
	pgdb "git-molva.ru/Molva/molva-backend/services/api_gateway/internal/database/postgres"
	dbtypes "git-molva.ru/Molva/molva-backend/services/api_gateway/internal/database/types"
)

type Client interface {
	CreateUser(ctx context.Context, request *dbtypes.UserSaveRequest) (*dbtypes.UserSaveResponse, error)
	GetClientValidation(ctx context.Context, request *dbtypes.ClientValidationGetRequest) (*dbtypes.ClientValidationGetResponse, error)

	GetVacancyIntegrationInfoById(ctx context.Context, vacancyId string) (string, *dbtypes.VacancyExtraFieldsTemplate, error)
	GetCompanyMetadataById(ctx context.Context, companyId string) (*dbtypes.CompanyMetadata, *dbtypes.CompanyExtraFieldsTemplate, error)

	GetVacancyList(ctx context.Context, request *dbtypes.VacancyListGetRequest) (*dbtypes.VacancyListGetResponse, error)
	CreateVacancy(ctx context.Context, request *dbtypes.VacancyCreateRequest) (*dbtypes.VacancyCreateResponse, error)
	UpdateVacancy(ctx context.Context, request *dbtypes.VacancyUpdateRequest) (*dbtypes.VacancyUpdateResponse, error)
	DeleteVacancy(ctx context.Context, request *dbtypes.VacancyDeleteRequest) (*dbtypes.VacancyDeleteResponse, error)
	SendVacancyToModeration(ctx context.Context, request *dbtypes.SendVacancyToModerationRequest) (*dbtypes.SendVacancyToModerationResponse, error)

	GetSubmissionList(ctx context.Context, request *dbtypes.SubmissionListGetRequest) (*dbtypes.SubmissionListGetResponse, error)
	CreateSubmission(ctx context.Context, request *dbtypes.SubmissionCreateRequest) (*dbtypes.SubmissionCreateResponse, error)
	UpdateSubmissionStatus(ctx context.Context, request *dbtypes.SubmissionStatusUpdateRequest) (*dbtypes.SubmissionStatusUpdateResponse, error)
	DeleteSubmission(ctx context.Context, request *dbtypes.SubmissionDeleteRequest) (*dbtypes.SubmissionDeleteResponse, error)

	GetCompanyList(ctx context.Context, request *dbtypes.CompanyListGetRequest) (*dbtypes.CompanyListGetResponse, error)
	GetCompanyById(ctx context.Context, request *dbtypes.CompanyByIdGetRequest) (*dbtypes.CompanyByIdGetResponse, error)
	CreateCompany(ctx context.Context, request *dbtypes.CompanyCreateRequest) (*dbtypes.CompanyCreateResponse, error)
	UpdateCompany(ctx context.Context, request *dbtypes.CompanyUpdateRequest) (*dbtypes.CompanyUpdateResponse, error)
	// DeleteDistributorCompany(ctx context.Context, request *dbtypes.DistributorCompanyDeleteRequest) (*dbtypes.DistributorCompanyDeleteResponse, error)

	GetProfileById(ctx context.Context, request *dbtypes.ProfileGetRequest) (*dbtypes.ProfileGetResponse, error)
	UpdateProfile(ctx context.Context, request *dbtypes.ProfileUpdateRequest) (*dbtypes.ProfileUpdateResponse, error)

	GetBalance(ctx context.Context, request *dbtypes.BalanceGetRequest) (*dbtypes.BalanceGetResponse, error)

	GetTransactionList(ctx context.Context, request *dbtypes.TransactionListGetRequest) (*dbtypes.TransactionListGetResponse, error)
	CreateTransaction(ctx context.Context, request *dbtypes.TransactionCreateRequest) (*dbtypes.TransactionCreateResponse, error)

	GetBankAccountList(ctx context.Context, request *dbtypes.BankAccountListGetRequest) (*dbtypes.BankAccountListGetResponse, error)
	CreateBankAccount(ctx context.Context, request *dbtypes.BankAccountCreateRequest) (*dbtypes.BankAccountCreateResponse, error)
	UpdateBankAccount(ctx context.Context, request *dbtypes.BankAccountUpdateRequest) (*dbtypes.BankAccountUpdateResponse, error)
	DeleteBankAccount(ctx context.Context, request *dbtypes.BankAccountDeleteRequest) (*dbtypes.BankAccountDeleteResponse, error)
}

func New(cType ClientType, c Config) (Client, error) {
	switch cType {
	case PostgresClientType:
		cfg, ok := c.(pgdb.PostgresConfig)
		if !ok {
			return nil, dberrors.ErrInvalidConfig
		}

		return pgdb.NewClient(cfg)

	default:
		return nil, dberrors.ErrClientType
	}
}
