<commit_before>module GobiertoPeople
  class PersonEventForm
    include ActiveModel::Model
    prepend ::GobiertoCommon::Trackable

    attr_accessor(
      :external_id,
      :site_id,
      :person_id,
      :title,
      :description,
      :starts_at,
      :ends_at,
      :state,
      :locations,
      :attendees
    )

    delegate :persisted?, to: :person_event

    validates :external_id, presence: true
    validates :title, presence: true
    validates :starts_at, :ends_at, presence: true
    validates :person, presence: true

    trackable_on :person_event

    notify_changed :state

    def save
      save_person_event if valid?
    end

    def site_id
      @site_id ||= person_event.site_id
    end

    def admin
      @admin ||= Admin.find_by(id: admin_id)
    end

    def site
      @site ||= Site.find_by(id: site_id)
    end

    def person_event
      @person_event ||= person.events.find_by(external_id: external_id).presence || build_person_event
    end

    def person_id
      @person_id ||= person_event.person_id
    end

    def person
      @person ||= person_class.find_by(id: person_id)
    end

    def locations
      @locations ||= person_event.locations.presence || [build_person_event_location]
    end

    def locations_attributes=(attributes)
      @locations ||= []

      attributes.each do |_, location_attributes|
        next if location_attributes["_destroy"] == "1"

        location = person_event.locations.detect{ |l| l.name == location_attributes[:name] } ||
          person_event_location_class.new(name: location_attributes[:name])

        @locations.push(location) if location.valid?
      end<commit_msg>Avoid circular dependency<commit_after>module GobiertoPeople
  class PersonEventForm
    include ActiveModel::Model
    prepend ::GobiertoCommon::Trackable

    attr_accessor(
      :external_id,
      :site_id,
      :person_id,
      :title,
      :description,
      :starts_at,
      :ends_at,
      :state,
      :locations,
      :attendees
    )

    delegate :persisted?, to: :person_event

    validates :external_id, presence: true
    validates :title, presence: true
    validates :starts_at, :ends_at, presence: true
    validates :person, presence: true

    trackable_on :person_event

    notify_changed :state

    def save
      save_person_event if valid?
    end

    def site_id
      @site_id ||= person_event.site_id
    end

    def admin
      @admin ||= Admin.find_by(id: admin_id)
    end

    def site
      @site ||= Site.find_by(id: site_id)
    end

    def person_event
      @person_event ||= person.events.find_by(external_id: external_id).presence || build_person_event
    end

    def person
      @person ||= person_class.find_by(id: person_id)
    end

    def locations
      @locations ||= person_event.locations.presence || [build_person_event_location]
    end

    def locations_attributes=(attributes)
      @locations ||= []

      attributes.each do |_, location_attributes|
        next if location_attributes["_destroy"] == "1"

        location = person_event.locations.detect{ |l| l.name == location_attributes[:name] } ||
          person_event_location_class.new(name: location_attributes[:name])

        @locations.push(location) if location.valid?
      end
{'fraction_non_alphanumeric': 0.09406392694063927, 'fraction_numerical': 0.0006088280060882801, 'mean_word_length': 2.8432748538011694, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5003388', 'n_tokens_mistral': 1047, 'n_tokens_neox': 1001, 'n_words': 220}