import { connect } from "mongoose";
import ServiceList from "../../Models/Services/Service";
import {
    CompanyServiceView,
    CreateServiceParams,
    UpdateServiceParams,
    FindServicesByCompanyParams,
    FindServicesByIdParams,
    IService,
    PaginateServicesParams,
    PaginateServicesResults,
    SetServiceFileParams,
    PublicServicesResults,
    SetPublishedStatusParams,
    FindServicesParams,
    ApplyDiscountParams,
    DeleteDiscountParams,
} from "../../Models/Services/Service.Interface";
import { TextObjectFilterResult } from "../../Models/TextObjectFilter.model";

export class ServicesService {
    public async setPublishedStatus(data: SetPublishedStatusParams): Promise<void> {
        await connect(`${process.env.DATABASE_CONNECTION}`);
        await ServiceList.setPublishedStatus(data);
    }

    public async createService(data: CreateServiceParams): Promise<IService> {
        await connect(`${process.env.DATABASE_CONNECTION}`);

        const newService = await ServiceList.createService(data);

        return newService;
    }

    public async updateService(data: UpdateServiceParams): Promise<void> {
        await connect(`${process.env.DATABASE_CONNECTION}`);
        await ServiceList.updateService(data);
    }

    public async paginateServices(data: PaginateServicesParams): Promise<PaginateServicesResults> {
        await connect(`${process.env.DATABASE_CONNECTION}`);

        const services = await ServiceList.paginate(data);

        return services;
    }

    public async findByCompanyId(data: FindServicesByCompanyParams): Promise<CompanyServiceView[]> {
        await connect(`${process.env.DATABASE_CONNECTION}`);

        const services = await ServiceList.findByCompanyId(data);

        return services;
    }

    public async findById(data: FindServicesByIdParams): Promise<CompanyServiceView> {
        await connect(`${process.env.DATABASE_CONNECTION}`);

        const service = await ServiceList.findById(data);

        return service;
    }

    public async setServiceImage(data: SetServiceFileParams): Promise<void> {
        await connect(`${process.env.DATABASE_CONNECTION}`);
        await ServiceList.setServiceImage(data);
    }

    public async publicServices(data: PaginateServicesParams): Promise<PublicServicesResults> {
        await connect(`${process.env.DATABASE_CONNECTION}`);
        const services = await ServiceList.publicServices(data);
        return services;
    }

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

        const services = await ServiceList.textObjectFilter(data);

        return services;
    }

    public async applyDiscount(data: ApplyDiscountParams): Promise<void> {
        await connect(`${process.env.DATABASE_CONNECTION}`);
        await ServiceList.applyDiscount(data);
    }

    public async deleteDiscount(data: DeleteDiscountParams): Promise<void> {
        await connect(`${process.env.DATABASE_CONNECTION}`);
        await ServiceList.deleteDiscount(data);
    }
}
