import { PlayProtocol } from '../manage/config.data';
import type { StreamingMediaModel } from '/@/api/camera/model/cameraModel';
import { BasicColumn, FormSchema } from '/@/components/Table';

export interface DrawerParams {
  createFlag: boolean;
  record?: StreamingMediaModel;
}

export const streamingMediaTypeMapping = {
  0: '海康ISC平台',
};

export const streamingMediaSSLMapping = {
  0: 'http',
  1: 'https',
};

export const formatSecret = (string: string) => {
  if (string.length < 6) {
    return string;
  } else {
    const reg = /(^\S{2}).*(\S{4}$)/;
    const prefix = string.match(reg)?.at(1);
    const suffix = string.match(reg)?.at(2);
    return `${prefix}${''.padStart(string.length - 6, '*')}${suffix}`;
  }
};

export const columnSchema: BasicColumn[] = [
  {
    title: '平台地址',
    dataIndex: 'host',
    width: 80,
  },
  {
    title: '用户Key',
    dataIndex: 'appKey',
    width: 80,
  },
  {
    title: '用户密钥',
    dataIndex: 'appSecret',
    width: 80,
    format(text) {
      return formatSecret(text);
    },
  },
  {
    title: '平台类型',
    dataIndex: 'type',
    width: 80,
    slots: { customRender: 'type' },
  },
  {
    title: '部署环境',
    dataIndex: 'ssl',
    width: 80,
    slots: { customRender: 'ssl' },
  },
];

export const formSchema: FormSchema[] = [
  {
    field: 'host',
    label: '平台地址',
    component: 'Input',
    colProps: { span: 8 },
  },
];

export const formDetailSchema: FormSchema[] = [
  {
    label: '平台类型',
    field: 'type',
    component: 'Select',
    rules: [{ required: true, message: '平台类型为必填项', type: 'number' }],
    componentProps: {
      options: [{ label: '海康ISC平台', value: 0 }],
      placeholder: '请输入选择平台类型',
    },
  },
  {
    label: '部署环境',
    field: 'ssl',
    component: 'RadioGroup',
    rules: [{ required: true, message: '流媒体部署环境为必填项', type: 'number' }],
    defaultValue: PlayProtocol.HTTP,
    componentProps: {
      defaultValue: PlayProtocol.HTTP,
      options: [
        { label: 'http', value: PlayProtocol.HTTP },
        { label: 'https', value: PlayProtocol.HTTPS },
      ],
    },
  },
  {
    label: '平台地址',
    field: 'host',
    component: 'Input',
    helpMessage: ['平台IP + 端口'],
    rules: [{ required: true, message: '平台地址为必填项' }],
    componentProps: {
      maxLength: 36,
      placeholder: '请输入平台地址',
    },
  },
  {
    label: '用户Key',
    field: 'appKey',
    component: 'Input',
    rules: [{ required: true, message: '用户Key为必填项' }],
    componentProps: {
      maxLength: 36,
      placeholder: '请输入用户Key',
    },
  },
  {
    label: '用户密钥',
    field: 'appSecret',
    component: 'Input',
    rules: [
      { required: true, message: '用户密钥为必填项' },
      { required: true, min: 20, message: '用户密钥不能少于20位字符' },
    ],
    componentProps: {
      maxLength: 36,
      placeholder: '请输入用户密钥',
    },
  },
];
