import { z } from '@hono/zod-openapi';

// 系统设置完整Schema
export const SystemSettingSchema = z.object({
  id: z.number().int().positive().openapi({
    description: '系统设置ID',
    example: 1
  }),
  settingKey: z.string().max(100).openapi({
    description: '设置键名',
    example: 'home_register_enabled'
  }),
  settingValue: z.string().nullable().openapi({
    description: '设置值',
    example: 'true'
  }),
  description: z.string().max(255).nullable().openapi({
    description: '设置描述',
    example: '首页注册功能开关'
  }),
  settingType: z.string().max(50).openapi({
    description: '设置类型',
    example: 'boolean'
  }),
  createdAt: z.coerce.date().openapi({
    description: '创建时间',
    example: '2024-01-01T00:00:00Z'
  }),
  updatedAt: z.coerce.date().openapi({
    description: '更新时间',
    example: '2024-01-01T00:00:00Z'
  })
});

// 创建系统设置DTO
export const CreateSystemSettingDto = z.object({
  settingKey: z.string().min(1, '设置键名不能为空').max(100, '设置键名最多100个字符').openapi({
    description: '设置键名',
    example: 'home_register_enabled'
  }),
  settingValue: z.string().nullable().openapi({
    description: '设置值',
    example: 'true'
  }),
  description: z.string().max(255, '描述最多255个字符').nullable().optional().openapi({
    description: '设置描述',
    example: '首页注册功能开关'
  }),
  settingType: z.string().max(50, '设置类型最多50个字符').default('string').openapi({
    description: '设置类型',
    example: 'boolean'
  })
});

// 更新系统设置DTO
export const UpdateSystemSettingDto = z.object({
  settingKey: z.string().min(1, '设置键名不能为空').max(100, '设置键名最多100个字符').optional().openapi({
    description: '设置键名',
    example: 'home_register_enabled'
  }),
  settingValue: z.string().nullable().optional().openapi({
    description: '设置值',
    example: 'false'
  }),
  description: z.string().max(255, '描述最多255个字符').nullable().optional().openapi({
    description: '设置描述',
    example: '首页注册功能开关'
  }),
  settingType: z.string().max(50, '设置类型最多50个字符').optional().openapi({
    description: '设置类型',
    example: 'boolean'
  })
});

// 批量更新设置DTO
export const BatchUpdateSettingsDto = z.object({
  settings: z.array(z.object({
    settingKey: z.string().min(1, '设置键名不能为空').max(100),
    settingValue: z.string().nullable(),
    description: z.string().max(255).nullable().optional(),
    settingType: z.string().max(50).optional()
  })).openapi({
    description: '批量设置列表',
    example: [
      {
        settingKey: 'home_register_enabled',
        settingValue: 'true',
        description: '首页注册功能开关',
        settingType: 'boolean'
      }
    ]
  })
});

// 获取设置值响应DTO
export const SettingValueResponse = z.object({
  settingKey: z.string().openapi({
    description: '设置键名',
    example: 'home_register_enabled'
  }),
  settingValue: z.string().nullable().openapi({
    description: '设置值',
    example: 'true'
  }),
  description: z.string().nullable().openapi({
    description: '设置描述',
    example: '首页注册功能开关'
  }),
  settingType: z.string().openapi({
    description: '设置类型',
    example: 'boolean'
  })
});