package guild

import (
	"context"
	"time"
)

func (s *service) LeaveGuild(ctx context.Context, guildID int64, userID int64) error {
	_, err := s.writeDB.GuildMembers.WithContext(ctx).
		Where(s.readDB.GuildMembers.GuildID.Eq(guildID)).
		Where(s.readDB.GuildMembers.UserID.Eq(userID)).
		Where(s.readDB.GuildMembers.Status.Eq(1)).
		Updates(map[string]any{s.readDB.GuildMembers.Status.ColumnName().String(): int32(2), s.readDB.GuildMembers.StartTime.ColumnName().String(): time.Now()})
	return err
}
