import { createActionGroup, emptyProps, props } from '@ngrx/store';
import { PaginationMeta } from '../../../models/api.model';
import { PurchaseRequest, CreatePurchaseRequest, UpdatePurchaseRequest } from '../../../models/purchase-request.model';

export const PurchaseRequestsActions = createActionGroup({
  source: 'Purchase Requests',
  events: {
    'Load Requests': props<{ page?: number; perPage?: number; force?: boolean }>(),
    'Load Requests Success': props<{ requests: PurchaseRequest[]; meta: PaginationMeta }>(),
    'Load Requests Failure': props<{ error: string }>(),

    'Load Request': props<{ id: number }>(),
    'Load Request Success': props<{ request: PurchaseRequest }>(),
    'Load Request Failure': props<{ error: string }>(),

    'Create Request': props<{ data: CreatePurchaseRequest }>(),
    'Create Request Success': props<{ request: PurchaseRequest }>(),
    'Create Request Failure': props<{ error: string }>(),

    'Update Request': props<{ id: number; data: UpdatePurchaseRequest }>(),
    'Update Request Success': props<{ request: PurchaseRequest }>(),
    'Update Request Failure': props<{ error: string }>(),

    'Delete Request': props<{ id: number }>(),
    'Delete Request Success': props<{ id: number }>(),
    'Delete Request Failure': props<{ error: string }>(),

    'Submit Request Approval': props<{ id: number }>(),
    'Approve Request': props<{ id: number }>(),
    'Reject Request': props<{ id: number; data?: { reason: string } }>(),
    'Convert Request To Order': props<{ id: number; data?: { supplier_id: number } }>(),
    'Cancel Request': props<{ id: number }>(),

    'Status Change Success': props<{ request: PurchaseRequest }>(),
    'Status Change Failure': props<{ error: string }>(),

    'Clear Requests Error': emptyProps(),
  },
});
