import { Schema } from "effect";
import { Expression, LocaleMarkdown } from "../../../../../share/expression.js";
import { Locale } from "../../../../../share/locale.js";
import { commonFieldFields, FieldOrientationSchema } from "../../../utils/common.js";
export const type = "com.shwfed.form.field.upload";
export const compatibilityDate = "2026-05-12";
export const metadata = {
  name: "\u6587\u4EF6\u4E0A\u4F20",
  icon: "fluent:cloud-arrow-up-20-regular",
  w: { initial: 8, min: 8, max: Infinity },
  h: { initial: 6, min: 6, max: Infinity, grow: true }
};
export const JSON_VAR = {
  type: "dyn",
  label: "HTTP \u54CD\u5E94\u4F53",
  description: "\u7B2C\u4E00\u6B65 `\u8BF7\u6C42` \u7684\u54CD\u5E94\u4F53\uFF08\u5DF2\u89E3\u6790 JSON\uFF09\uFF1B\u7528\u4E8E\u6784\u9020\u7B2C\u4E8C\u6B65\u4E0B\u8F7D\u8BF7\u6C42"
};
function configureWithJson(configure) {
  return (env) => {
    configure(env);
    env.registerVariable("json", JSON_VAR.type, { description: JSON_VAR.description });
  };
}
export function schema(configure) {
  const CelBool = Expression({ configure, resultType: "bool" });
  const CelHttpRequest = Expression({ configure, resultType: "HttpRequest" });
  const CelDownloadRequest = Expression({ configure: configureWithJson(configure), resultType: "HttpRequest" });
  const LocaleMd = LocaleMarkdown({ configure });
  return Schema.Struct({
    type: Schema.Literal(type),
    compatibilityDate: Schema.Literal(compatibilityDate),
    ...commonFieldFields(configure),
    label: Schema.optional(Locale.annotations({
      title: "\u6807\u7B7E",
      description: "\u5B57\u6BB5\u524D\u5C55\u793A\u7684\u6587\u672C\uFF1B\u7559\u7A7A\u5219\u4E0D\u6E32\u67D3\u6807\u7B7E"
    })),
    description: Schema.optional(LocaleMd.annotations({
      title: "\u8BF4\u660E",
      description: "\u5C55\u793A\u5728\u4E0A\u4F20\u533A\u57DF\u4E0A\u65B9\u7684\u591A\u8BED\u8A00\u8BF4\u660E\uFF0C\u652F\u6301 Markdown \u4E0E `{{ form.foo }}` \u63D2\u503C"
    })),
    placeholder: Schema.optional(Locale.annotations({
      title: "\u5360\u4F4D\u7B26",
      description: "\u4E0A\u4F20\u533A\u57DF\u4E3A\u7A7A\u65F6\u7684\u63D0\u793A\u6587\u672C"
    })),
    tooltip: Schema.optional(Locale.annotations({
      title: "\u63D0\u793A",
      description: "\u9F20\u6807\u60AC\u505C\u5728\u6807\u7B7E\u4E0A\u65F6\u5C55\u793A\u7684\u8BF4\u660E"
    })),
    orientation: Schema.optional(FieldOrientationSchema),
    binding: Schema.optional(Schema.String.pipe(Schema.minLength(1)).annotations({
      title: "\u7ED1\u5B9A\u8DEF\u5F84",
      description: "\u5199\u5165\u8868\u5355\u72B6\u6001\u7684 `dot-prop` \u8DEF\u5F84\uFF0C\u4F8B\u5982 `attachments`\uFF1B\u7559\u7A7A\u5219\u4E3A\u975E\u53D7\u63A7\u5B57\u6BB5"
    })),
    disabled: Schema.optional(CelBool.annotations({
      title: "\u7981\u7528\u6761\u4EF6",
      description: "\u8FD4\u56DE `true` \u65F6\u4E0A\u4F20\u533A\u57DF\u4ECD\u7136\u6E32\u67D3\u4F46\u4E0D\u53EF\u64CD\u4F5C"
    })),
    readonly: Schema.optional(CelBool.annotations({
      title: "\u53EA\u8BFB\u6761\u4EF6",
      description: "\u8FD4\u56DE `true` \u65F6\u4EC5\u4EE5\u6587\u4EF6\u5217\u8868\u5C55\u793A\u5F53\u524D\u503C\uFF0C\u4E0D\u5141\u8BB8\u589E\u5220"
    })),
    multiple: Schema.optional(Schema.Boolean.annotations({
      title: "\u5141\u8BB8\u591A\u6587\u4EF6",
      description: "\u5F00\u542F\u540E\u53EF\u4E00\u6B21\u9009\u62E9/\u62D6\u5165\u591A\u4E2A\u6587\u4EF6\uFF1B\u5173\u95ED\u65F6\u65B0\u6587\u4EF6\u4F1A\u66FF\u6362\u5DF2\u9009\u6587\u4EF6"
    })),
    accept: Schema.optional(Schema.Array(Schema.String).annotations({
      title: "\u5141\u8BB8\u7684\u6587\u4EF6\u7C7B\u578B",
      description: "\u5141\u8BB8\u4E0A\u4F20\u7684 MIME \u7C7B\u578B\u5217\u8868\uFF1B\u7559\u7A7A\u8868\u793A\u4E0D\u9650\u5236"
    })),
    maxFileSize: Schema.optional(Schema.Number.pipe(Schema.positive()).annotations({
      title: "\u5355\u6587\u4EF6\u5927\u5C0F\u9650\u5236",
      description: "\u5355\u4E2A\u6587\u4EF6\u5141\u8BB8\u7684\u6700\u5927\u5B57\u8282\u6570\uFF1B\u8D85\u8FC7\u6B64\u9650\u5236\u7684\u6587\u4EF6\u4F1A\u88AB\u62D2\u7EDD"
    })),
    maxTotalSize: Schema.optional(Schema.Number.pipe(Schema.positive()).annotations({
      title: "\u603B\u5927\u5C0F\u9650\u5236",
      description: "\u6240\u6709\u5DF2\u9009\u6587\u4EF6\u7D2F\u8BA1\u7684\u6700\u5927\u5B57\u8282\u6570\uFF1B\u65B0\u589E\u5BFC\u81F4\u8D85\u51FA\u65F6\u4F1A\u88AB\u62D2\u7EDD"
    })),
    maxFiles: Schema.optional(Schema.Number.pipe(Schema.int(), Schema.positive()).annotations({
      title: "\u6587\u4EF6\u6570\u91CF\u9650\u5236",
      description: "\u5141\u8BB8\u540C\u65F6\u4E0A\u4F20\u7684\u6700\u5927\u6587\u4EF6\u6570\uFF1B\u8FBE\u5230\u4E0A\u9650\u540E\u65B0\u589E\u6587\u4EF6\u4F1A\u88AB\u62D2\u7EDD"
    })),
    template: Schema.optional(Schema.Struct({
      request: CelHttpRequest.annotations({
        title: "\u8BF7\u6C42",
        description: "\u8FD4\u56DE `HttpRequest` \u7684 CEL \u8868\u8FBE\u5F0F\u3002\u672A\u914D\u7F6E\u300C\u4E0B\u8F7D\u8BF7\u6C42\u300D\u65F6\u76F4\u63A5\u53D1\u8D77\u5E76\u4E0B\u8F7D\u5176\u54CD\u5E94\uFF1B\u914D\u7F6E\u4E86\u300C\u4E0B\u8F7D\u8BF7\u6C42\u300D\u65F6\u4F5C\u4E3A\u83B7\u53D6\u4E0B\u8F7D\u51ED\u636E\u7684\u7B2C\u4E00\u6B65\u8BF7\u6C42"
      }),
      download: Schema.optional(CelDownloadRequest.annotations({
        title: "\u4E0B\u8F7D\u8BF7\u6C42",
        description: "\u53EF\u9009\u7684\u7B2C\u4E8C\u6B65\uFF1A\u8FD4\u56DE `HttpRequest` \u7684 CEL \u8868\u8FBE\u5F0F\uFF0C\u53EF\u901A\u8FC7 `json` \u5F15\u7528\u7B2C\u4E00\u6B65\u7684\u54CD\u5E94\u4F53\uFF0C\u4F8B\u5982\u7528 `json.data.key` \u6784\u9020\u771F\u6B63\u7684\u4E0B\u8F7D\u8BF7\u6C42"
      }))
    }).annotations({
      title: "\u4E0B\u8F7D\u6A21\u677F",
      description: "\u4E0B\u8F7D\u6A21\u677F\u7684\u8BF7\u6C42\u914D\u7F6E\uFF1B\u8BBE\u7F6E\u540E\u4F1A\u5728\u4E0A\u4F20\u533A\u57DF\u65C1\u6E32\u67D3\u4E0B\u8F7D\u6A21\u677F\u6309\u94AE"
    })),
    templateIcon: Schema.optional(Schema.String.pipe(Schema.minLength(1)).annotations({
      title: "\u6A21\u677F\u6309\u94AE\u56FE\u6807",
      description: "Iconify \u56FE\u6807\u6807\u8BC6\u7B26\uFF0C\u4F8B\u5982 `fluent:arrow-download-20-regular`\uFF1B\u7559\u7A7A\u65F6\u4F7F\u7528\u9ED8\u8BA4\u56FE\u6807"
    })),
    templateLabel: Schema.optional(Locale.annotations({
      title: "\u6A21\u677F\u6309\u94AE\u6587\u672C",
      description: "\u4E0B\u8F7D\u6A21\u677F\u6309\u94AE\u4E0A\u7684\u672C\u5730\u5316\u6587\u672C\uFF1B\u7559\u7A7A\u65F6\u4F7F\u7528\u300C\u4E0B\u8F7D\u6A21\u677F\u300D"
    }))
  }).annotations({
    title: "UploadField",
    description: "\u6587\u4EF6\u4E0A\u4F20\u5B57\u6BB5"
  });
}
