import {
  defineListRouteStateSchema,
  enumListRouteField,
  positiveIntegerListRouteField,
  stringListRouteField,
} from '#/composables/useListRouteState';

type ApprovalTabName = 'flow' | 'initiated' | 'pending' | 'processed';
type ApprovalActionType = '' | 'DELETE' | 'OFFLINE' | 'PUBLISH';
type ApprovalResourceType = '' | 'AGENT' | 'BOT' | 'KNOWLEDGE' | 'WORKFLOW';
type ApprovalStatus =
  | ''
  | 'APPROVED'
  | 'DISABLED'
  | 'ENABLED'
  | 'PENDING'
  | 'PROCESSING'
  | 'REJECTED'
  | 'REVOKED';

interface ApprovalListRouteState {
  actionType: ApprovalActionType;
  keyword: string;
  name: string;
  pageNumber: number;
  pageSize: number;
  resourceType: ApprovalResourceType;
  status: ApprovalStatus;
  tab: ApprovalTabName;
}

const approvalListRouteSchema =
  defineListRouteStateSchema<ApprovalListRouteState>({
    path: '/sys/approval',
    fields: {
      actionType: enumListRouteField(['DELETE', 'OFFLINE', 'PUBLISH'], ''),
      keyword: stringListRouteField(),
      name: stringListRouteField(),
      pageNumber: positiveIntegerListRouteField({ defaultValue: 1 }),
      pageSize: positiveIntegerListRouteField({
        allowedValues: [10, 20, 50, 100],
        defaultValue: 10,
      }),
      resourceType: enumListRouteField(
        ['AGENT', 'BOT', 'KNOWLEDGE', 'WORKFLOW'],
        '',
      ),
      status: enumListRouteField(
        [
          'APPROVED',
          'DISABLED',
          'ENABLED',
          'PENDING',
          'PROCESSING',
          'REJECTED',
          'REVOKED',
        ],
        '',
      ),
      tab: enumListRouteField(
        ['flow', 'pending', 'processed', 'initiated'],
        'flow',
      ),
    },
  });

export { approvalListRouteSchema };
export type { ApprovalListRouteState, ApprovalStatus, ApprovalTabName };
