package guild

import (
	"context"
)

func (s *service) ModifyGuild(ctx context.Context, id int64, in ModifyGuildInput) error {
	g, err := s.readDB.Guild.WithContext(ctx).Where(s.readDB.Guild.ID.Eq(id)).First()
	if err != nil {
		return err
	}
	if in.Name != "" {
		g.Name = in.Name
	}
	if in.Description != "" {
		g.Description = in.Description
	}
	if in.JoinMode != 0 {
		g.JoinMode = in.JoinMode
	}
	if in.ConsumeLimit != 0 {
		g.ConsumeLimit = in.ConsumeLimit
	}
	if in.AvatarURL != "" {
		g.AvatarURL = in.AvatarURL
	}
	if in.IsOpen != 0 {
		g.IsOpen = in.IsOpen
	}
	if in.Status != 0 {
		g.Status = in.Status
	}
	return s.writeDB.Guild.WithContext(ctx).Save(g)
}
