/*
  component.h

  Copyright (c) 2021 Kevin Matz (kevin.matz@gmail.com)

  Permission is hereby granted, free of charge, to any person obtaining a copy
  of this software and associated documentation files (the "Software"), to deal
  in the Software without restriction, including without limitation the rights
  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  copies of the Software, and to permit persons to whom the Software is
  furnished to do so, subject to the following conditions:

  The above copyright notice and this permission notice shall be included in all
  copies or substantial portions of the Software.

  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  SOFTWARE.
*/
#pragma once

#include "uuid/uuid.h"

#include <string>

namespace ACN {

/**
 * @brief The Component class
 *  The process, program or application corresponding to a single ACN endpoint.
 *  All messages in ACN are sent and received by a component.
 *
 *  See [Arch] for a more complete definition.
 */
class Component {
public:
  /**
   * @brief Component
   * @param cid
   */
  Component(UUID::uuid cid = UUID::uuid())
    : fctn_(std::string("OpenLCP ACN Component"))
    , uacn_(std::string())
    , cid_(cid)
  {};

  /**
   * @brief cid
   * @return
   */
  const UUID::uuid  cid()       const { return cid_;  }
  /**
   * @brief fixedName fixed component name
   * @return
   */
  const std::string fixedName() const { return fctn_; }
  /**
   * @brief userName  user-asigned name
   * @return
   */
  const std::string userName()  const { return uacn_; }
  /**
   * @brief component name, either user asigned or fixed.
   * @return
   */
  const std::string name()      const { return uacn_.empty() ? fctn_ : uacn_; }
  /**
   * @brief set the user asigned name
   * @param s
   */
  void assignUserName(const std::string s) { uacn_ = s; }

protected:
  /**
   *  EPI 19: ACN Discovery on IP Networks
   *  3. Component Name Strings
   *  Each component shall maintain two text identifier strings intended to
   *  indicate the function of the component in human readable terms for
   *  browsing purposes.
  */

  /**
   * @brief 3.1. Fixed Component Type Name (FCTN)
   * shall be a UTF-8 string that is assigned during manufacture.
   */
  std::string fctn_;

  /**
   * @brief 3.2. User Assigned Component Name (UACN)
   * shall be a UTF-8 string that may be assigned by the user.
   */
  std::string uacn_;

private:
  const UUID::uuid cid_;
};

}; // ACN
