import type { VbenFormSchema } from '#/adapter/form';
import type { VxeTableGridOptions } from '#/adapter/vxe-table';

import {
  getLevelName,
  getUpgradeStatusName,
  getUpgradeTypeName,
} from '#/utils/agent';

export function useUpgradeColumns(): VxeTableGridOptions['columns'] {
  return [
    {
      field: 'id',
      title: 'ID',
      width: 80,
    },
    {
      field: 'agent_id',
      title: '代理ID',
      width: 100,
    },
    {
      field: 'from_level',
      title: '原等级',
      width: 100,
      formatter: ({ cellValue }: { cellValue: number }) => {
        return getLevelName(cellValue);
      },
    },
    {
      field: 'to_level',
      title: '目标等级',
      width: 100,
      formatter: ({ cellValue }: { cellValue: number }) => {
        return getLevelName(cellValue);
      },
    },
    {
      field: 'upgrade_type',
      title: '升级类型',
      width: 120,
      formatter: ({ cellValue }: { cellValue: number }) => {
        return getUpgradeTypeName(cellValue);
      },
    },
    {
      field: 'upgrade_fee',
      title: '升级费用',
      width: 120,
      formatter: ({ cellValue }: { cellValue: number }) =>
        `¥${cellValue.toFixed(2)}`,
    },
    {
      field: 'rebate_amount',
      title: '返佣金额',
      width: 120,
      formatter: ({ cellValue }: { cellValue: number }) =>
        `¥${cellValue.toFixed(2)}`,
    },
    {
      field: 'status',
      title: '状态',
      width: 100,
      cellRender: {
        name: 'CellTag',
        options: [
          { value: 1, color: 'warning', label: '待处理' },
          { value: 2, color: 'success', label: '已完成' },
          { value: 3, color: 'error', label: '已失败' },
        ],
      },
    },
    {
      field: 'create_time',
      title: '创建时间',
      width: 160,
      sortable: true,
    },
  ] as const;
}

export function useUpgradeFormSchema(): VbenFormSchema[] {
  return [
    {
      component: 'InputNumber',
      fieldName: 'agent_id',
      label: '代理ID',
    },
    {
      component: 'Select',
      fieldName: 'upgrade_type',
      label: '升级类型',
      componentProps: {
        allowClear: true,
        options: [
          { label: '自主付费', value: 1 },
          { label: '钻石升级下级', value: 2 },
        ],
      },
    },
    {
      component: 'Select',
      fieldName: 'status',
      label: '状态',
      componentProps: {
        allowClear: true,
        options: [
          { label: '待处理', value: 1 },
          { label: '已完成', value: 2 },
          { label: '已失败', value: 3 },
        ],
      },
    },
  ];
}

