import { db } from "@pkg/db";
import type {
  CreateCustomerInfoPayload,
  UpdateCustomerInfoPayload,
} from "./data";
import { CustomerInfoRepository } from "./repository";

export class CustomerInfoUseCases {
  private repo: CustomerInfoRepository;

  constructor(repo: CustomerInfoRepository) {
    this.repo = repo;
  }

  async getAllCustomerInfo() {
    return this.repo.getAllCustomerInfo();
  }

  async getCustomerInfoById(id: number) {
    return this.repo.getCustomerInfoById(id);
  }

  async getCustomerInfoByOrderId(oid: number) {
    return this.repo.getCustomerInfoByOrderId(oid);
  }

  async createCustomerInfo(payload: CreateCustomerInfoPayload) {
    return this.repo.createCustomerInfo(payload);
  }

  async updateCustomerInfo(payload: UpdateCustomerInfoPayload) {
    return this.repo.updateCustomerInfo(payload);
  }

  async deleteCustomerInfo(id: number) {
    return this.repo.deleteCustomerInfo(id);
  }
}

export function getCustomerInfoUseCases() {
  return new CustomerInfoUseCases(new CustomerInfoRepository(db));
}
