import { Provide } from '@midwayjs/decorator';
import { BaseService } from '@cool-midway/core';
import { InjectEntityModel } from '@midwayjs/typeorm';
import { In, Repository } from 'typeorm';
import * as _ from 'lodash';
import { ChannelEntity } from '../entity/channel';

@Provide()
export class ChannelService extends BaseService {
  @InjectEntityModel(ChannelEntity)
  channelEntity: Repository<ChannelEntity>;

  async getChannelList() {
    return await this.channelEntity.find({
      where: {
        status: 1
      },
      select: ['id', 'name', 'code', 'payType', 'currency']
    })
  }

  async getByCodes(codes) {
    return await this.channelEntity.findBy({
      status: 1,
      code: In(codes)
    });
  }

  async queryByCode(code) {
    return await this.channelEntity.findOneBy({
      code,
    });
  }
}
