import {
    CLIENT_ACCOUNT_MOVEMENT_STATUS,
    CLIENT_ACCOUNT_PAYMENT_METHODS,
} from "./ClientAccountMovements.model";

export enum PAYMENT_METHODS_CLIENT_ACCOUNT {
    CLIENT_ACCOUNT = "ACCOUNT",
}

export type PAYMENT_METHODS = CLIENT_ACCOUNT_PAYMENT_METHODS | PAYMENT_METHODS_CLIENT_ACCOUNT;

export type FindPaymentsParams = {
    id?: string;
    clientId?: string;
    clientIds?: string[];
    companyId?: string;
    appointmentId?: string;
    employeeId?: string;
    serviceId?: string;
    status?: CLIENT_ACCOUNT_MOVEMENT_STATUS;
    method?: PAYMENT_METHODS;
    startDate?: Date;
    endDate?: Date;
    proccessDate?: PAYMENT_PROCCESS_DATE;
    sessionUser: string;
};

export type PaginatePaymentsParams = FindPaymentsParams & {
    page: number;
    limit: number;
};

export type PaginatePaymentsResults = {
    data: IPayment[];
    page: number;
    pages: number;
};

export enum PAYMENT_PROCCESS_DATE {
    NOW = "now",
    APPOINTMENT = "appointment",
}

export type CreatePaymentParams = {
    amount: number;
    method: PAYMENT_METHODS;
    status: CLIENT_ACCOUNT_MOVEMENT_STATUS;
    appointmentId: string;
    description?: string;
    proccessDate: PAYMENT_PROCCESS_DATE;
    sessionUser: string;
};

export type CreatePaymentExtraParams = CreatePaymentParams & {
    clientId: string;
    companyId: string;
    employeeId: string;
    serviceId: string;
};

export type DeletePaymentParams = {
    id: string;
    sessionUser: string;
};

export type GetAppointmentPaymentsParams = {
    appointmentId: string;
    sessionUser: string;
};

export type MarkAsPayedParams = {
    appointmentId: string;
    method: PAYMENT_METHODS;
    sessionUser: string;
};

export interface PaginatePaymentsView {
    id: string;
    appointmentId: string;
    appointmentDate: Date;
    clientId: string;
    clientName: string;
    employeeId: string;
    employeeName: string;
    serviceId: string;
    serviceName: string;
    price: number;
    status: CLIENT_ACCOUNT_MOVEMENT_STATUS;
    method: PAYMENT_METHODS;
    description: string;
    createdAt: Date;
}

export type PaginateNotPayedAppointmentsParams = FindPaymentsParams & {
    page: number;
    limit: number;
};

export type PaginateNotPayedAppointmentsResult = {
    data: PaginatePaymentsView[];
    page: number;
    pages: number;
};

export type PaginatePaymentsViewParams = FindPaymentsParams & {
    page: number;
    limit: number;
};

export type PaginatePaymentsViewResults = {
    data: PaginatePaymentsView[];
    page: number;
    pages: number;
};

export interface IPayment {
    id: string;
    _id: string;
    amount: number;
    status: CLIENT_ACCOUNT_MOVEMENT_STATUS;
    method: PAYMENT_METHODS;
    clientId: string;
    companyId: string;
    employeeId: string;
    serviceId: string;
    appointmentId: string;
    description: string;
    createdAt: Date;
    updatedAt: Date;
}

export const paymentMethods = [
    {
        id: CLIENT_ACCOUNT_PAYMENT_METHODS.CASH,
        name: "Efectivo",
        description: "Efectivo",
    },
    {
        id: PAYMENT_METHODS_CLIENT_ACCOUNT.CLIENT_ACCOUNT,
        name: "Cuenta Corriente",
        description: "Dinero en cuenta",
    },
    {
        id: CLIENT_ACCOUNT_PAYMENT_METHODS.BANK_TRANSFER,
        name: "Transferencia",
        description: "Transferencia",
    },
    {
        id: CLIENT_ACCOUNT_PAYMENT_METHODS.CREDIT_CARD,
        name: "Tarjeta de crédito",
        description: "Tarjeta de crédito",
    },
    {
        id: CLIENT_ACCOUNT_PAYMENT_METHODS.DEBIT_CARD,
        name: "Tarjeta de débito",
        description: "Tarjeta de débito",
    },
    {
        id: CLIENT_ACCOUNT_PAYMENT_METHODS.OTHER,
        name: "Otro",
        description: "Otro",
    },
];


export type NotPayedReportResult = {
    items: PaginatePaymentsView[];
    totalAmount: number;
};

export type PaymentsReportResult = {
    items: PaginatePaymentsView[];
    totalAmount: number;
};
