/** Production Orders resource – Production BC. */

import type { AxiosInstance } from 'axios';
import type { ProductionOrderDTO, CreateProductionOrderRequest } from '@effigenix/types';

export type Priority = 'LOW' | 'NORMAL' | 'HIGH' | 'URGENT';

export const PRIORITY_LABELS: Record<Priority, string> = {
  LOW: 'Niedrig',
  NORMAL: 'Normal',
  HIGH: 'Hoch',
  URGENT: 'Dringend',
};

export type { ProductionOrderDTO, CreateProductionOrderRequest };

const BASE = '/api/production/production-orders';

export function createProductionOrdersResource(client: AxiosInstance) {
  return {
    async create(request: CreateProductionOrderRequest): Promise<ProductionOrderDTO> {
      const res = await client.post<ProductionOrderDTO>(BASE, request);
      return res.data;
    },

    async release(id: string): Promise<ProductionOrderDTO> {
      const res = await client.post<ProductionOrderDTO>(`${BASE}/${id}/release`);
      return res.data;
    },
  };
}

export type ProductionOrdersResource = ReturnType<typeof createProductionOrdersResource>;
