import { withHeaders } from "@/record-management/services/api/withHeaders";
import axiosInstance from "@/shared/services/axiosInstance";
import { AxiosResponse } from "axios";
export interface positiontypeItems {
  id: string;
  unitId: string;
  positionTypeId: string;
  canReceiveRecord: boolean;
  canCreateBankRecord?: boolean;
  timeframe: string;
  createdAt: string;
  updatedAt: string;
}

export interface PositionTypeConfigurationDto {
  id: string;
  unitId: string;
  positionTypeId: string;
  canReceiveRecord: boolean;
  canCreateBankRecord?: boolean;
  timeframe: string;
  createdAt: string;
  updatedAt: string;
  organizationId?: string;
  canAssignRecord?: boolean;
}

export interface PositionTypeConfigurationListResponse {
  count: number;
  items: PositionTypeConfigurationDto[];
}

export interface CreatePositionTypeConfigurationPayload {
  positionTypeId: string;
  timeframe: string;
  organizationId: string;
  unitId?: string;
  canReceiveRecord?: boolean;
  canCreateBankRecord?: boolean;
  canAssignRecord?: boolean;
}

export interface UpdatePositionTypeConfigurationPayload {
  unitId?: string;
  positionTypeId?: string;
  timeframe?: string;
  organizationId?: string;
  canReceiveRecord?: boolean;
  canCreateBankRecord?: boolean;
  canAssignRecord?: boolean;
}

// GET: List by unitId
export const getPositionTypeConfigurationsByUnitId = async (
  unitId: string,
): Promise<AxiosResponse<PositionTypeConfigurationListResponse>> => {
  return axiosInstance.get(`/position-type-configurations/list/${unitId}`, {
    headers: withHeaders(),
  });
};

// GET: Single by id
export const getPositionTypeConfigurationById = async (
  id: string,
): Promise<AxiosResponse<PositionTypeConfigurationDto>> => {
  return axiosInstance.get(`/position-type-configurations/${id}`, {
    headers: withHeaders(),
  });
};

// POST: Create
export const createPositionTypeConfiguration = async (
  payload: CreatePositionTypeConfigurationPayload,
): Promise<AxiosResponse<PositionTypeConfigurationDto>> => {
  return axiosInstance.post(`/position-type-configurations`, payload, {
    headers: withHeaders(),
  });
};

// PUT: Update by id
export const updatePositionTypeConfiguration = async (
  id: string,
  payload: UpdatePositionTypeConfigurationPayload,
): Promise<AxiosResponse<PositionTypeConfigurationDto>> => {
  return axiosInstance.put(`/position-type-configurations/${id}`, payload, {
    headers: withHeaders(),
  });
};
