import type { FindPageResponse } from '../basic'

import { postForm } from '#/api/http'

import { BasicService } from '../basic'

class PlatformService extends BasicService {
  // 分页查询
  override async findPage(
    current: number,
    size: number,
    condition: any,
  ): Promise<FindPageResponse> {
    const data = (await super.findPage(current, size, condition)) as any
    for (const item of data.rows) {
      try {
        item.config = JSON.parse(item.config)
      } catch {
        item.config = {}
      }
    }
    return data
  }

  async reload(id: any) {
    await postForm('/sys/platform/reload', {
      id,
    })
  }

  protected findPageUrl(): string {
    return '/sys/platform/list'
  }

  protected removeUrl(): string {
    return '/sys/platform/batch/delete'
  }

  protected saveOrUpdateUrl(): string {
    return '/sys/platform/saveOrUpdate'
  }

  protected override switchKeyValues() {
    return [
      {
        key: 'status',
        trueValue: 0,
        falseValue: 1,
      },
    ]
  }
}

export const platformService = new PlatformService()
