package controller

import (
	"crawler/model"
	"net/http"

	"github.com/gin-gonic/gin"
)

type Company struct {
	Kobis model.Kobis
}

/**
 * 영화사 목록 조회
 * /company/searchCompanyList
 */
func (this *Company) SearchCompanyList(c *gin.Context) {
	var req model.SearchCompanyListParams

	if err := c.ShouldBind(&req); err != nil {
		c.JSON(http.StatusBadRequest, err.Error())
		return
	}

	data, err := this.Kobis.CompanyListAPI(req)
	if err != nil {
		c.JSON(http.StatusBadRequest, err.Error())
		return
	}

	c.JSON(http.StatusOK, gin.H{
		"total": data.CompanyListResult.TotCnt,
		"rows":  len(data.CompanyListResult.CompanyList),
		"list":  data.CompanyListResult.CompanyList,
	})
}

/**
 * 영화사 상세 조회
 * /company/searchCompanyInfo
 */
func (this *Company) SearchCompanyInfo(c *gin.Context) {
	var req model.SearchCompanyInfoParams

	if err := c.ShouldBind(&req); err != nil {
		c.JSON(http.StatusBadRequest, err.Error())
		return
	}

	data, err := this.Kobis.CompanyInfoAPI(req)
	if err != nil {
		c.JSON(http.StatusBadRequest, err.Error())
		return
	}

	c.JSON(http.StatusOK, gin.H{
		"info": data.CompanyInfoResult.CompanyInfo,
	})
}
