import { connect } from "mongoose";
import ClientsList from "../../Models/Clients/Clients";
import {
    ClientMergeParams,
    CreateCustomClientParams,
    DeleteClientParams,
    FindClientByIdParams,
    IClient,
    OrganizationClientsResults,
    OrganizationClientView,
    PaginateOrganizationClientsParams,
    UpdateClientParams,
} from "../../Models/Clients/Clients.Interface";
import {
    TextObjectFilterParams,
    TextObjectFilterResult,
} from "../../Models/TextObjectFilter.model";

export class ClientsService {
    public async deleteClient(data: DeleteClientParams): Promise<void> {
        await connect(`${process.env.DATABASE_CONNECTION}`);
        await ClientsList.deleteClient(data);
    }

    public async clientMerge(data: ClientMergeParams): Promise<void> {
        await connect(`${process.env.DATABASE_CONNECTION}`);
        await ClientsList.clientMerge(data);
    }

    public async createCustomClient(data: CreateCustomClientParams): Promise<IClient> {
        await connect(`${process.env.DATABASE_CONNECTION}`);

        const newClient = await ClientsList.createCustomClient(data);

        return newClient;
    }

    public async updateClient(data: UpdateClientParams): Promise<void> {
        await connect(`${process.env.DATABASE_CONNECTION}`);
        await ClientsList.updateClient(data);
    }

    public async findOrganizationClients(
        data: PaginateOrganizationClientsParams
    ): Promise<OrganizationClientsResults> {
        await connect(`${process.env.DATABASE_CONNECTION}`);

        const clients = await ClientsList.findOrganizationClients(data);

        return clients;
    }

    public async textObjectFilter(data: TextObjectFilterParams): Promise<TextObjectFilterResult[]> {
        await connect(`${process.env.DATABASE_CONNECTION}`);

        const clients = await ClientsList.textObjectFilter(data);

        return clients;
    }

    public async findClientById(data: FindClientByIdParams): Promise<OrganizationClientView> {
        await connect(`${process.env.DATABASE_CONNECTION}`);

        const clients = await ClientsList.findClientById(data);

        return clients;
    }
}
