import { IClientAccountMovement } from "../ClientAccountMovements/ClientAccountMovements.Interface";
import { IClientAccountDocument } from "./ClientAccounts.Adapter.Mongoose";

export type FindClientAccountsParams = {
    clientId: string;
    sessionUser: string;
};

export type CreateClientAccountParams = {
    clientId: string;
    amount: number;
    sessionUser: string;
};

export type DeleteClientAccountParams = {
    clientId: string;
    checkCashOnAccount?: boolean;
    sessionUser: string;
};

export type DeleteClientsAccountsByCompanyParams = {
    companyId: string;
};

export type ClientAccountReportItem = {
    date: Date;
    description: string;
    credit: number;
    debit: number;
    balance: number;
};

export type ClientAccountReport = {
    organizacionName: string;
    organizationId: string;
    clientId: string;
    clientName: string;
    balance: number;
    dateFrom: Date;
    dateTo: Date;
    data: ClientAccountReportItem[];
};

export type GetPrevoiusBalanceParams = {
    clientId: string;
    date: Date;
    sessionUser: string;
};

export type GetClientAccountReportParams = {
    clientId: string;
    dateFrom: Date;
    dateTo: Date;
    sessionUser: string;
};

export interface ClientAccountView {
    id: string;
    clientId: string;
    amount: number;
    lastMovements: IClientAccountMovement[];
}

export interface IClientAccount {
    id?: string;
    clientId: string;
    amount: number;
}

export interface IClientAccountsAdapter {
    create(data: CreateClientAccountParams): Promise<IClientAccount>;
    delete(id: string): Promise<void>;
    find(filters: FindClientAccountsParams): Promise<IClientAccount[]>;
    findOne(filters: FindClientAccountsParams): Promise<IClientAccountDocument | null>;
}

export interface IClientAccountsManager {
    clientAccounts: IClientAccountsAdapter;
    createClientAccount(data: CreateClientAccountParams): Promise<IClientAccount>;
    findById(data: FindClientAccountsParams): Promise<IClientAccount>;
    deleteClientAccount(data: DeleteClientAccountParams): Promise<void>;
    deleteClientsAccountsByCompany(data: DeleteClientsAccountsByCompanyParams): Promise<void>;
    clientAccountView(data: FindClientAccountsParams): Promise<ClientAccountView>;
    getAvailableAmount(data: FindClientAccountsParams): Promise<number>;
    getPrevoiusBalance(data: GetPrevoiusBalanceParams): Promise<number>;
    getAccountReport(data: GetClientAccountReportParams): Promise<ClientAccountReport>;
}
