/*
 *
 * Copyright (c) 2025. Jeffery Hsu - Achievement Report Generator
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program. If not, see <https://www.gnu.org/licenses/>.
 *
 */

import { ICourse } from '@renderer/types'

export class Course implements ICourse {
  private _campus: string
  private _className: string
  private _credit: number
  private _id: string
  private _master: string
  private _name: string
  private _teacher: string

  constructor(
    campus: string,
    className: string,
    credit: number | string,
    id: string,
    master: string,
    name: string,
    teacher: string
  ) {
    this._campus = campus
    this._className = className
    this._credit = Number(credit)
    this._id = id
    this._master = master
    this._name = name
    this._teacher = teacher
  }

  public static factory() {
    return new Course('', '', 0, '', '', '', '')
  }

  public static factoryToImpl(): ICourse {
    return { campus: '', className: '', credit: 0, id: '', master: '', name: '', teacher: '' }
  }

  public static factoryFromImpl(impl: ICourse) {
    return new Course(
      impl.campus,
      impl.className,
      Number(impl.credit),
      impl.id,
      impl.master,
      impl.name,
      impl.teacher
    )
  }

  public setFromImpl(course: ICourse) {
    this._campus = course.campus
    this._className = course.className
    this._credit = Number(course.credit)
    this._id = course.id
    this._master = course.master
    this._name = course.name
    this._teacher = course.teacher
  }

  public getCurrImpl(): ICourse {
    return {
      campus: this._campus,
      className: this._className,
      credit: this._credit,
      id: this._id,
      master: this._master,
      name: this._name,
      teacher: this._teacher
    }
  }

  public isEmpty() {
    return !(
      this._id &&
      this._master &&
      this._name &&
      this._teacher &&
      this._credit &&
      this._className &&
      this._campus
    )
  }

  set campus(value: string) {
    this._campus = value
  }

  set className(value: string) {
    this._className = value
  }

  set credit(value: number | string) {
    this._credit = Number(value)
  }

  set id(value: string) {
    this._id = value
  }

  set master(value: string) {
    this._master = value
  }

  set name(value: string) {
    this._name = value
  }

  set teacher(value: string) {
    this._teacher = value
  }
  get campus(): string {
    return this._campus
  }

  get className(): string {
    return this._className
  }

  get credit(): number {
    return this._credit
  }

  get id(): string {
    return this._id
  }

  get master(): string {
    return this._master
  }

  get name(): string {
    return this._name
  }

  get teacher(): string {
    return this._teacher
  }
}
