package backstage_service

import (
	"youngmini_server/app/dao/backstage_dao"
	"youngmini_server/app/model/backstage_model"
)

var Brand = serviceBrand{}

type serviceBrand struct{}

// CreatBrand  创建品牌信息
func (s *serviceBrand) CreatBrand(brand *backstage_model.BrandReq) error {
	err := backstage_dao.CreatBrand(brand)
	if err != nil {
		return err
	}
	return nil
}

// DeleteBrand 根据ID删除品牌信息
func (s *serviceBrand) DeleteBrand(brandId string) error {
	_, err := backstage_dao.FindByIdBrand(brandId)
	if err != nil {
		return err
	}
	err = backstage_dao.DeleteBrand(brandId)
	if err != nil {
		return err
	}
	return err
}

// UpdateBrand 更新品牌信息
func (s *serviceBrand) UpdateBrand(brand *backstage_model.BrandResp) error {
	err := backstage_dao.UpdateBrand(brand)
	if err != nil {
		return err
	}
	return err
}

// FindByIdBrand 根据ID查询单条信息
func (s *serviceBrand) FindByIdBrand(brandId string) (*backstage_model.BrandResp, error) {
	res, err := backstage_dao.FindByIdBrand(brandId)
	if err != nil {
		return nil, err
	}
	return res, nil
}

// FindAllBrand 查询所有，分页查询
func (s *serviceBrand) FindAllBrand(indexPage int, pageSize int) ([]*backstage_model.BrandResp, error) {
	res, err := backstage_dao.FindAllBrand(indexPage, pageSize)
	if err != nil {
		return nil, err
	}
	return res, nil
}
