import { AugmentedActionContext } from "./_module";
import { RouteConfig } from "#/route";
import { RouteRecordRaw } from "vue-router";

import { IUser } from "#/api";

// state 定义
type State = {
  store: Storage;
  pageTitle: string;
  roles: string[];
  routes: RouteConfig[];
  addRoutes: RouteConfig[];
  user: Partial<IUser>;
  officials: SelectOptions<number>;
  platforms: SelectOptions<string>;
  collapsed: boolean;
  selectTime: any[];
  setTemStepOne: { [key: string]: any };
};

// mutation 定义
enum MutationType {
  setRoles = "setRoles",
  setRoutes = "setRoutes",
  setUser = "setUser",
  setOfficial = "setOfficial",
  setPlatforms = "setPlatforms",
  setCollapsed = "setCollapsed",
  setSelectTime = "setSelectTime",
  setTemStepOne = "setTemStepOne",
}

type Mutations<S = State> = {
  [MutationType.setRoles](state: S, roles: string[]): void;
  [MutationType.setRoutes](state: S, routes: RouteConfig[]): void;
  [MutationType.setUser](state: S, user: Partial<IUser>): void;
  [MutationType.setOfficial](state: S, officials: SelectOptions<number>): void;
  [MutationType.setPlatforms](state: S, platforms: SelectOptions<string>): void;
  [MutationType.setCollapsed](state: S, platforms: boolean): void;
  [MutationType.setSelectTime](state: S, platforms: any[]): void;
  [MutationType.setTemStepOne](state: S, setTemStepOne: any[]): void;
};

// action 定义
enum ActionType {
  generatorRoutes = "generatorRoutes",
  getUserRoles = "getUserRoles",
  doLogin = "doLogin",
  doSaveOfficial = "doSaveOfficial",
  doSavePlatforms = "doSavePlatforms",
}

type Actions = {
  [ActionType.generatorRoutes](
    { commit }: AugmentedActionContext,
    roles: string[]
  ): Promise<RouteConfig[]>;
  [ActionType.getUserRoles]({
    commit,
  }: AugmentedActionContext): Promise<string[]>;
  [ActionType.doLogin]({ commit }: AugmentedActionContext, user: unknown): void;
  [ActionType.doSaveOfficial]({ commit }: AugmentedActionContext): void;
  [ActionType.doSavePlatforms]({ commit }: AugmentedActionContext): void;
};

// getter 定义
type Getters = {
  permissionRoutes(state: State): RouteRecordRaw[];
  userRoles(state: State): string[];
  user(state: State): Partial<IUser>;
  pageTitle(state: State): string;
  officials(state: State): SelectOptions<number>;
  platforms(state: State): SelectOptions<string>;
  collapsed(state: State): boolean;
  selectTime(state: State): any[];
  getOneTemp(state: State): { [key: string]: any };
};

export { State, Mutations, MutationType, Actions, ActionType, Getters };
