import { AllbidsScrapModel } from "../models/allbids-scrap-model.js";
import { GraysScrapModel } from "../models/grays-scrap-model.js";
import { LangtonsScrapModel } from "../models/langtons-scrap-model.js";
import { LawsonsScrapModel } from "../models/lawsons-scrap-model.js";
import { PicklesScrapModel } from "../models/pickles-scrap-model.js";

export class ScrapConfigsService {
  static scrapModel(scrapConfig, page) {
    switch (scrapConfig.web_bid.origin_url) {
      case "https://www.grays.com": {
        return new GraysScrapModel({
          ...scrapConfig,
          scrap_config_id: scrapConfig.id,
          page: page,
        });
      }
      case "https://www.langtons.com.au": {
        return new LangtonsScrapModel({
          ...scrapConfig,
          scrap_config_id: scrapConfig.id,
          page: page,
        });
      }
      case "https://www.lawsons.com.au": {
        return new LawsonsScrapModel({
          ...scrapConfig,
          scrap_config_id: scrapConfig.id,
          page: page,
        });
      }
      case "https://www.pickles.com.au": {
        return new PicklesScrapModel({
          ...scrapConfig,
          scrap_config_id: scrapConfig.id,
          page: page,
        });
      }
      case "https://www.allbids.com.au": {
        return new AllbidsScrapModel({
          ...scrapConfig,
          scrap_config_id: scrapConfig.id,
          page: page,
        });
      }
      default: {
        return null;
      }
    }
  }

  static scrapModels(data, page) {
    return data
      .map((item) => this.scrapModel(item, page))
      .filter((item) => !!item);
  }
}
