<?php

namespace Booktics\Service\Helpers;

use Booktics\Models\Team_Member_Model;
use Booktics\Taxonomy\Category;

class Service_Helper {

    /**
     * Get team member details for given team member IDs.
     *
     * @param array $team_member_ids
     * @return array
     */
    public static function team_member_details( $team_member_ids ) {
        $details = array();
        foreach ( $team_member_ids as $id ) {
            $member = ( new Team_Member_Model() )->find( $id );
            if ( $member ) {
                $member = $member->to_array();
                $details[] = array(
                    'id' => $member['id'],
                    'display_name' => $member['display_name'],
                    'email' => $member['email'],
                    'image' => $member['image'],
                );
            }
        }
        return $details;
    }

    /**
     * Get category details for given category IDs.
     *
     * @param array $category_ids
     * @return array
     */
    public static function category_details( $category_ids ) {
        $category_ids = array_filter( $category_ids );
        $details = array();
        foreach ( $category_ids as $id ) {
            $category = \get_term( $id, ( new Category() )->get_name() );
            if ( $category ) {
                $category = $category->to_array();
                $details[] = array(
                    'id' => $category['term_id'],
                    'name' => $category['name'],
                );
            }
        }
        return $details;
    }
}
