import { call, crud } from 'store/utils/api';
import { config } from 'config/general';

const api = {
  login: (options: Record<string, any>): Promise =>
    call('admins/login', 'POST', {
      baseUrl: config.api.cmsBase,
      ...options,
    }),
  logout: (options: Record<string, any>): Promise =>
    call('admins/logout', 'GET', {
      baseUrl: config.api.cmsBase,
      ...options,
    }),
  me: (options: Record<string, any>): Promise =>
    call('admins/me', 'GET', {
      baseUrl: config.api.cmsBase,
      ...options,
    }),
  list: (options: Record<string, any>): Promise =>
    call('pages', 'GET', {
      baseUrl: config.api.cmsBase,
      ...options,
    }),
  update: (options: Record<string, any>): Promise =>
    call(`pages/${options.id}`, 'PUT', {
      baseUrl: config.api.cmsBase,
      ...options,
    }),
  add: (options: Record<string, any>): Promise =>
    call('pages', 'POST', {
      baseUrl: config.api.cmsBase,
      ...options,
    }),
  delete: (options: Record<string, any>): Promise =>
    call(`pages/${options.id}`, 'DELETE', {
      baseUrl: config.api.cmsBase,
      ...options,
    }),
};

export default api;
