import { IModelsConfig, PageActions } from "./.types";

const PAGE_SIZE = 10;

export const pageActions: PageActions = {
  hasDetailPage: true,
  editOnNewPage: true,
  detailOnNewPage: true,
  createOnNewPage: true,
};

export const modelsConfig: IModelsConfig = {
  Product: {
    metadata: {
      nameKeys: ["name"],
      pageActions,
    },
    table: {
      toolbar: {
        searchBar: {
          fields: ["id", "name", "sku"],
        },
        actions: [
          { action: "REFRESH", desc: "refresh" },
          { action: "SETTING", desc: "setting" },
          {
            action: "EXPORT",
            desc: "Export",
            fields: ["*", "!update_time"],
          },
        ],
      },
      header: {
        filter: ["published"],
        sorter: ["id", "name", "price", "sku"],
      },
      fields: ["*", "!create_time"],
      rowSelection: {
        actions: [
          {
            action: "INSERT",
            desc: "insert",
          },
          {
            action: "CHANGE_STATUS",
            desc: "publish",
            values: { published: "PUBLISHED" },
          },
          { action: "DELETE", desc: "delete" },
          { action: "EXPORT", desc: "export" },
        ],
      },
      rowActions: {
        visibleNum: 2,
        actions: [
          {
            action: "EDIT",
            desc: "edit",
          },
          {
            action: "CHANGE_STATUS",
            desc: "publish",
            values: { published: "PUBLISHED" },
            when: { published: "UNPUBLISH" },
          },
          {
            action: "CHANGE_STATUS",
            desc: "unpublish",
            values: { published: "UNPUBLISH" },
            when: { published: "PUBLISHED" },
          },
          { action: "DELETE", desc: "delete" },
        ],
      },
      params: {
        pageSize: PAGE_SIZE,
      },
    },
    form: {
      fields: ["*", "!id", "!create_time", "!update_time"],
      initialValues: {
        sku: "999",
      },
      reaction: {
        sku: {
          toggle: [
            {
              props: {
                value: "111",
                readonly: true,
                hidden: false,
              },
              when: {
                name: "111",
                price: 111,
              },
            },
            {
              props: {
                value: "222",
                readonly: true,
                hidden: true,
              },
              when: {
                name: "222",
                price: 222,
              },
            },
          ],
          defaultProps: {
            readonly: false,
            hidden: false,
          },
        },
      },
    },
    show: {
      fields: ["*"],
    },
  },
  User: {
    metadata: {
      nameKeys: ["name"],
      pageActions,
    },
    table: {
      toolbar: {
        searchBar: {
          fields: ["id", "name"],
          containsFields: ["name"],
          placeholder: "id, name",
        },
        actions: [
          { action: "REFRESH", desc: "Refresh" },
          { action: "SETTING", desc: "Setting" },
          {
            action: "EXPORT",
            desc: "export",
            fields: [
              "*",
              "!create_time",
              "!posts.*",
              "_count.posts",
              "!comments.*",
              "_count.comments",
              "!notice.*",
              "notice.id",
            ],
          },
        ],
      },
      header: {
        filter: [],
        sorter: ["id"],
      },
      fields: [
        "*",
        "!create_time",
        "!posts.*",
        "_count.posts",
        "!comments.*",
        "_count.comments",
        "!notice.*",
        "notice",
      ],
      rowSelection: {
        actions: [
          { action: "INSERT", desc: "Insert" },

          { action: "DELETE", desc: "Delete" },
          { action: "EXPORT", desc: "Export" },
        ],
      },
      rowActions: {
        visibleNum: 2,
        actions: [
          {
            action: "EDIT",
            desc: "Edit",
          },

          { action: "DELETE", desc: "Delete" },
        ],
      },
      params: {
        pageSize: PAGE_SIZE,
      },
    },
    form: {
      fields: [
        "*",
        "!id",
        "!create_time",
        "!update_time",
        "notice.*",
        "posts.*",
        "comments.*",
      ],
    },
    show: {
      fields: [
        "*",
        "!create_time",
        "!posts.*",
        "_count.posts",
        "!comments.*",
        "_count.comments",
        "!notice.*",
        "notice",
      ],
    },
  },
  Post: {
    metadata: {
      nameKeys: ["title"],
      pageActions,
    },
    table: {
      toolbar: {
        searchBar: {
          fields: ["id", "title"],
          containsFields: ["title"],
          placeholder: "id, title",
        },
        actions: [
          { action: "REFRESH", desc: "Refresh" },
          { action: "SETTING", desc: "Setting" },
          {
            action: "EXPORT",
            desc: "export",
            fields: [
              "*",
              "!create_time",
              "!content",
              "!comments.*",
              "_count.comments",
              "!medias.*",
              "_count.medias",
              "!author.*",
              "author.id",
            ],
          },
        ],
      },
      header: {
        filter: ["author"],
        sorter: ["id"],
      },
      fields: [
        "*",
        "!create_time",
        "!content",
        "!comments.*",
        "_count.comments",
        "!medias.*",
        "_count.medias",
        "!author.*",
        "author",
      ],
      rowSelection: {
        actions: [
          { action: "INSERT", desc: "Insert" },

          { action: "DELETE", desc: "Delete" },
          { action: "EXPORT", desc: "Export" },
        ],
      },
      rowActions: {
        visibleNum: 2,
        actions: [
          {
            action: "EDIT",
            desc: "Edit",
          },

          { action: "DELETE", desc: "Delete" },
        ],
      },
      params: {
        pageSize: PAGE_SIZE,
      },
    },
    form: {
      fields: [
        "*",
        "!id",
        "!create_time",
        "!update_time",
        "author.*",
        "comments.*",
        "medias.*",
      ],
    },
    show: {
      fields: [
        "*",
        "!create_time",
        "!comments.*",
        "_count.comments",
        "!medias.*",
        "_count.medias",
        "!author.*",
        "author",
      ],
    },
  },
  Media: {
    metadata: {
      nameKeys: ["id"],
      pageActions,
    },
    table: {
      toolbar: {
        searchBar: {
          fields: ["id"],
          containsFields: [],
          placeholder: "id",
        },
        actions: [
          { action: "REFRESH", desc: "Refresh" },
          { action: "SETTING", desc: "Setting" },
          {
            action: "EXPORT",
            desc: "export",
            fields: [
              "*",
              "!create_time",
              "!image",
              "!video_thumbnail",
              "!attachment",
              "!desc",
              "!post.*",
              "post.id",
            ],
          },
        ],
      },
      header: {
        filter: [],
        sorter: ["id"],
      },
      fields: [
        "*",
        "!create_time",
        "!image",
        "!video_thumbnail",
        "!attachment",
        "!desc",
        "!post.*",
        "post",
      ],
      rowSelection: {
        actions: [
          { action: "INSERT", desc: "Insert" },

          { action: "DELETE", desc: "Delete" },
          { action: "EXPORT", desc: "Export" },
        ],
      },
      rowActions: {
        visibleNum: 2,
        actions: [
          {
            action: "EDIT",
            desc: "Edit",
          },

          { action: "DELETE", desc: "Delete" },
        ],
      },
      params: {
        pageSize: PAGE_SIZE,
      },
    },
    form: {
      fields: ["*", "!id", "!create_time", "!update_time", "post.*"],
    },
    show: {
      fields: ["*", "!create_time", "!post.*", "post"],
    },
  },
  Comment: {
    metadata: {
      nameKeys: ["id"],
      pageActions,
    },
    table: {
      toolbar: {
        searchBar: {
          fields: ["id"],
          containsFields: [],
          placeholder: "id",
        },
        actions: [
          { action: "REFRESH", desc: "Refresh" },
          { action: "SETTING", desc: "Setting" },
          {
            action: "EXPORT",
            desc: "export",
            fields: [
              "*",
              "!create_time",
              "!content",
              "!posts.*",
              "_count.posts",
              "!user.*",
              "user.id",
            ],
          },
        ],
      },
      header: {
        filter: [],
        sorter: ["id"],
      },
      fields: [
        "*",
        "!create_time",
        "!content",
        "!posts.*",
        "_count.posts",
        "!user.*",
        "user",
      ],
      rowSelection: {
        actions: [
          { action: "INSERT", desc: "Insert" },

          { action: "DELETE", desc: "Delete" },
          { action: "EXPORT", desc: "Export" },
        ],
      },
      rowActions: {
        visibleNum: 2,
        actions: [
          {
            action: "EDIT",
            desc: "Edit",
          },

          { action: "DELETE", desc: "Delete" },
        ],
      },
      params: {
        pageSize: PAGE_SIZE,
      },
    },
    form: {
      fields: ["*", "!id", "!create_time", "!update_time", "user.*", "posts.*"],
    },
    show: {
      fields: [
        "*",
        "!create_time",
        "!posts.*",
        "_count.posts",
        "!user.*",
        "user",
      ],
    },
  },
  Notice: {
    metadata: {
      nameKeys: ["title"],
      pageActions,
    },
    table: {
      toolbar: {
        searchBar: {
          fields: ["id", "title"],
          containsFields: ["title"],
          placeholder: "id, title",
        },
        actions: [
          { action: "REFRESH", desc: "Refresh" },
          { action: "SETTING", desc: "Setting" },
          {
            action: "EXPORT",
            desc: "export",
            fields: ["*", "!create_time", "!content", "!user.*", "user.id"],
          },
        ],
      },
      header: {
        filter: [],
        sorter: ["id"],
      },
      fields: ["*", "!create_time", "!content", "!user.*", "user"],
      rowSelection: {
        actions: [
          { action: "INSERT", desc: "Insert" },

          { action: "DELETE", desc: "Delete" },
          { action: "EXPORT", desc: "Export" },
        ],
      },
      rowActions: {
        visibleNum: 2,
        actions: [
          {
            action: "EDIT",
            desc: "Edit",
          },

          { action: "DELETE", desc: "Delete" },
        ],
      },
      params: {
        pageSize: PAGE_SIZE,
      },
    },
    form: {
      fields: ["*", "!id", "!create_time", "!update_time", "user.*"],
    },
    show: {
      fields: ["*", "!create_time", "!user.*", "user"],
    },
  },
};
