package platform_chain_service

import (
	"bwallet/models"
)

type PlatformChain struct {
	Id         int
	PlatformId int
	ChainId    int
	IsPrimary  int
}

func (c *PlatformChain) Get() (*models.PlatformChain, error) {

	platformChain, err := models.GetPlatformChain(c.Id)
	if err != nil {
		return nil, err
	}

	return platformChain, nil
}

func (c *PlatformChain) GetAll() ([]*models.PlatformChain, error) {
	var platformChain []*models.PlatformChain

	platformChain, err := models.GetPlatformChains(c.getMaps())
	if err != nil {
		return nil, err
	}

	return platformChain, nil
}

func (c *PlatformChain) ExistById() (bool, error) {
	return models.ExistPlatformChainById(c.Id)
}

func (c *PlatformChain) Count() (int, error) {
	return models.GetPlatformChainTotal(c.getMaps())
}

func (c *PlatformChain) DeleteByCondition() error {
	return models.DeleteByPlatformIdChainId(c.getMaps())
}

func (c *PlatformChain) getMaps() (map[string]interface{}) {
	maps := make(map[string]interface{})

	if c.PlatformId != 0 {
		maps["platform_id"] = c.PlatformId
	}

	if c.ChainId != 0 {
		maps["chain_id"] = c.ChainId
	}

	if c.IsPrimary != 0 {
		maps["is_primary"] = c.IsPrimary
	}

	return maps
}
