import { advertising } from "@kit.AdsKit";


interface BannerParam {
  adWidth: number,
  adHeight: number
}

export class BannerAd {
  adParam: advertising.AdRequestParams = {
    // 广告类型：横幅广告
    adType: 8,
    // 'testw6vs28auh3'为测试专用的广告位ID，App正式发布时需要改为正式的广告位ID
    adId: 'testw6vs28auh3',
    // 广告位宽
    adWidth: 360,
    // 广告位高
    adHeight: 57,
  };
  adOptions: advertising.AdOptions = {
    // 设置广告内容分级上限
    adContentClassification: 'A'
  };
  adDisplayOptions: advertising.AdDisplayOptions = {
    // 是否静音，默认不静音
    mute: false,
    // 广告轮播的时间间隔，单位ms，取值范围[30000, 120000]
    refreshTime: 30000
  }
  ratio: number = 1;
  adWidth: number = -1;
  adHeight: number = -1;

  constructor(param?: BannerParam) {
    if (param && param.adWidth > 0 && param.adHeight > 0) {
      this.adParam.adWidth = param.adWidth
      this.adParam.adHeight = param.adHeight
    }
    if (this.adParam?.adWidth && typeof (this.adParam?.adWidth) === 'number' && this.adParam?.adWidth > 0) {
      this.adWidth = this.adParam?.adWidth;
    }
    if (this.adParam?.adHeight && typeof (this.adParam?.adHeight) === 'number' && this.adParam?.adHeight > 0) {
      this.adHeight = this.adParam?.adHeight;
    }
    if (this.adWidth > 0 && this.adHeight > 0) {
      this.ratio = this.adWidth / this.adHeight;
    }
  }
}